package com.sofwin.configer;

import com.sofwin.controller.DeptController;
import com.sofwin.service.*;
import org.apache.dubbo.config.ProtocolConfig;
import org.apache.dubbo.config.ReferenceConfig;
import org.apache.dubbo.config.RegistryConfig;
import org.apache.dubbo.config.bootstrap.DubboBootstrap;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.EnableAspectJAutoProxy;
import org.springframework.transaction.annotation.EnableTransactionManagement;
import org.springframework.web.servlet.config.annotation.EnableWebMvc;

/**
 * @packageName: com.sofwin.configer
 * @user: andyliu
 * @date: 2023/5/10 16:08
 * @email 115176513@qq.com
 * @description: TODO
 */
@Configuration
@ComponentScan(basePackages = "com.sofwin")
@EnableAspectJAutoProxy
@EnableTransactionManagement
@EnableWebMvc
public class RootConfiger {

    private DubboBootstrap dubboBootstrap;
    public RootConfiger(){
         this.dubboBootstrap = DubboBootstrap.getInstance()
                .application("system")
                .registry(new RegistryConfig("zookeeper://192.168.206.250:2181"))
                .protocol(new ProtocolConfig("dubbo", 20883));
    }

    @Bean
    public DeptService getDeptService(){
        DubboBootstrap bootstrap = this.dubboBootstrap;
        ReferenceConfig<DeptService> config = new ReferenceConfig<>();
        config.setInterface(DeptService.class);
        bootstrap.reference(config);
        return config.get();
    }
    @Bean
    public UserService getUserService(){
        DubboBootstrap bootstrap = this.dubboBootstrap;
        ReferenceConfig<UserService> config = new ReferenceConfig<>();
        config.setInterface(UserService.class);
        bootstrap.reference(config);
        return config.get();
    }
    @Bean
    public RoleService getRoleService(){
        DubboBootstrap bootstrap = this.dubboBootstrap;
        ReferenceConfig<RoleService> config = new ReferenceConfig<>();
        config.setInterface(RoleService.class);
        bootstrap.reference(config);
        return config.get();
    }
    @Bean
    public ResourceService getResourceService(){
        DubboBootstrap bootstrap = this.dubboBootstrap;
        ReferenceConfig<ResourceService> config = new ReferenceConfig<>();
        config.setInterface(ResourceService.class);
        bootstrap.reference(config);
        return config.get();
    }
    @Bean
    public OperatorService getOperatorService(){
        DubboBootstrap bootstrap = this.dubboBootstrap;
        ReferenceConfig<OperatorService> config = new ReferenceConfig<>();
        config.setInterface(OperatorService.class);
        bootstrap.reference(config);
        return config.get();
    }
}
